
//
//  HMStatusRetweetedView.m
//  黑马微博-wzy
//
//  Created by Mac on 2017/2/17.
//  Copyright © 2017年 Mac. All rights reserved.
//

#import "HMStatusRetweetedView.h"
#import "HMStatusRetweetedFrame.h"
#import "HMStatus.h"
#import "HMUser.h"
#import "HMStatusPhotosView.h"


@interface HMStatusRetweetedView()

//昵称
@property (nonatomic, weak) UILabel *nameLabel;
//正文
@property (nonatomic, weak) UILabel *textLabel;

//图片
@property (nonatomic, strong) HMStatusPhotosView *photosView;

@end


@implementation HMStatusRetweetedView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.image = [UIImage resizedImage:@"timeline_retweet_background"];
        self.userInteractionEnabled = YES;
        
        
        [self setupView];
    }
    return self;
}

- (void)setupView{
  //1.昵称
    UILabel *nameLabel = [[UILabel alloc] init];
    nameLabel.textColor = HMColor(74, 102, 105);
    nameLabel.font = HMStatusRetweetedNameFont;
    [self addSubview:nameLabel];
    self.nameLabel = nameLabel;
    
    //2.正文
    UILabel *textLabel = [[UILabel alloc] init];
    textLabel.font = HMStatusRetweetedTextFont;
    textLabel.numberOfLines = 0;
    [self addSubview:textLabel];
    self.textLabel = textLabel;
    
    //3.图片
    HMStatusPhotosView *photosView = [[HMStatusPhotosView alloc] init];
    [self addSubview:photosView];
    self.photosView = photosView;
}

//根据传进来的微博数据,计算转发微博的frame
//重写 retweetedFrame  的setter 方法
- (void)setRetweetedFrame:(HMStatusRetweetedFrame *)retweetedFrame{
    _retweetedFrame = retweetedFrame;
    
    self.frame = retweetedFrame.retweetedF;
    //取出微博数据
    HMStatus *retweetedStatus = retweetedFrame.retweetedStatus;
    
    //获取用户数据
    HMUser *user = retweetedStatus.user;
    
    //1.昵称
    self.nameLabel.text = [NSString stringWithFormat:@"@%@", user.name];
//    self.nameLabel.backgroundColor = [UIColor greenColor];
    self.nameLabel.frame = retweetedFrame.nameFrame;
    
    //2. 正文
    self.textLabel.text = retweetedStatus.text;
    self.textLabel.frame = retweetedFrame.textFrame;
    
    //3.图片
    if (retweetedStatus.pic_urls.count) {
        //如果有图片,设置其frame,且其隐藏属性 为NO
        self.photosView.frame = retweetedFrame.photosFrame;
        self.photosView.pic_urls = retweetedStatus.pic_urls;
        self.photosView.hidden = NO;
    }else{
        //如果没有图片,其隐藏属性 为YES
        self.photosView.hidden = YES;
        
    }
}


@end
